22. Planning Your Variables
Planning Your Variables
Question:
Start Quiz:
Solution:
INSTRUCTOR NOTE:
Here "#" = "number"
In programming languages a constant is a value that is never changed or modified during the course of the program. In Java you can force a value not to be changed by using the keyword final
. For example:
final int POINTS_FOR_FREE_THROW = 1;
Then if you wrote the following, you'd get an error:
POINTS_FOR_FREE_THROW = 100;
Note, by convention, constants have all capitalized letters in their names. Also, instead of spaces or camel-case, underscores are used between words. You can declare variables as constants to keep yourself from accidentally changing the value of a variable.
For a more detailed explanation of final variables, check out Wikipedia and here.